﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OptionsForm
{
    public partial class Options : Form
    {
        private MineSweeper mine;

        public Options(MineSweeper m)
        {
            mine = m;
            InitializeComponent();
        }

        private void CustomButtonCheckedChanged(object sender, EventArgs e)
        {
            var option = (RadioButton) sender;
            if (option.Checked)
                NumericUpDownsEnabled();
        }

        private void NumericUpDownsEnabled()
        {
            WidthCount.Enabled = true;
            HeightCount.Enabled = true;
            BombCount.Enabled = true;
        }

        private void Accept_Click(object sender, EventArgs e)
        {
            var rbSelected = group.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);
            String str;
            if (mine.BombCount == 9 && mine.HeightButtonCount == 9 && mine.WidthButtonCount == 9)
            {
                str = "SmallButton";

            }
            else if (mine.BombCount == 16 && mine.HeightButtonCount == 16 && mine.WidthButtonCount == 40)
            {
                str = "MediumButton";
            }
            else if (mine.BombCount == 16 && mine.HeightButtonCount == 30 && mine.WidthButtonCount == 99)
            {
                str = "LargeButton";
            }
            else
            {
                str = "CustomButton";
            }
            if (rbSelected.Name.Equals(str, StringComparison.InvariantCultureIgnoreCase))
                Close();
            switch (rbSelected.Name.Substring(0, 4))
            {
                case "Smal":
                    mine.BombCount = 9;
                    mine.HeightButtonCount = 9;
                    mine.WidthButtonCount = 9;
                    break;
                case "Medi":
                    mine.BombCount = 40;
                    mine.HeightButtonCount = 16;
                    mine.WidthButtonCount = 16;
                    break;
                case "Larg":
                    mine.BombCount = 99;
                    mine.HeightButtonCount = 30;
                    mine.WidthButtonCount = 16;
                    break;
                case "Cust":
                    mine.BombCount = (int) BombCount.Value;
                    mine.HeightButtonCount = (int) HeightCount.Value;
                    mine.WidthButtonCount = (int) WidthCount.Value;
                    break;

            }
            Close();
        }
    }
}
